package com.resource.base.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
import org.springframework.web.cors.CorsConfiguration;

import java.util.ArrayList;
import java.util.List;
@Configuration
@ConfigurationProperties(
        prefix = "jines",
        ignoreUnknownFields = false
)
@PropertySources({@PropertySource(
        value = {"classpath:git.properties"},
        ignoreResourceNotFound = true
), @PropertySource(
        value = {"classpath:META-INF/build-info.properties"},
        ignoreResourceNotFound = true
)})
public class MyProperties {
    

        private final MyProperties.Http http = new MyProperties.Http();
        private final MyProperties.Security security = new MyProperties.Security();
        private final CorsConfiguration cors = new CorsConfiguration();

        public MyProperties() {
        }

        public MyProperties.Http getHttp() {
            return this.http;
        }

        public MyProperties.Security getSecurity() {
            return this.security;
        }

        public CorsConfiguration getCors() {
            return this.cors;
        }

        public static class Security {
            private final MyProperties.Security.ClientAuthorization clientAuthorization = new MyProperties.Security.ClientAuthorization();
            private final MyProperties.Security.Authentication authentication = new MyProperties.Security.Authentication();
            private final MyProperties.Security.RememberMe rememberMe = new MyProperties.Security.RememberMe();
            private final List<String> authorizePermitAll = new ArrayList();
            private final List<String> authorize = new ArrayList();

            public Security() {
            }

            public MyProperties.Security.ClientAuthorization getClientAuthorization() {
                return this.clientAuthorization;
            }

            public MyProperties.Security.Authentication getAuthentication() {
                return this.authentication;
            }

            public MyProperties.Security.RememberMe getRememberMe() {
                return this.rememberMe;
            }

            public List<String> getAuthorizePermitAll() {
                return this.authorizePermitAll;
            }

            public List<String> getAuthorize() {
                return this.authorize;
            }

            public static class RememberMe {
                private String key;

                public RememberMe() {
                    this.key = JinesDefaults.Security.RememberMe.key;
                }

                public String getKey() {
                    return this.key;
                }

                public void setKey(String key) {
                    this.key = key;
                }
            }

            public static class Authentication {
                private final MyProperties.Security.Authentication.Jwt jwt = new MyProperties.Security.Authentication.Jwt();

                public Authentication() {
                }

                public MyProperties.Security.Authentication.Jwt getJwt() {
                    return this.jwt;
                }

                public static class Jwt {
                    private String secret;
                    private long tokenValidityInSeconds;
                    private long tokenValidityInSecondsForRememberMe;

                    public Jwt() {
                        this.secret = JinesDefaults.Security.Authentication.Jwt.secret;
                        this.tokenValidityInSeconds = 1800L;
                        this.tokenValidityInSecondsForRememberMe = 2592000L;
                    }

                    public String getSecret() {
                        return this.secret;
                    }

                    public long getTokenValidityInSeconds() {
                        return this.tokenValidityInSeconds;
                    }

                    public long getTokenValidityInSecondsForRememberMe() {
                        return this.tokenValidityInSecondsForRememberMe;
                    }

                    public void setSecret(String secret) {
                        this.secret = secret;
                    }

                    public void setTokenValidityInSeconds(long tokenValidityInSeconds) {
                        this.tokenValidityInSeconds = tokenValidityInSeconds;
                    }

                    public void setTokenValidityInSecondsForRememberMe(long tokenValidityInSecondsForRememberMe) {
                        this.tokenValidityInSecondsForRememberMe = tokenValidityInSecondsForRememberMe;
                    }
                }
            }

            public static class ClientAuthorization {
                private String accessTokenUri;
                private String tokenServiceId;
                private String clientId;
                private String clientSecret;

                public ClientAuthorization() {
                    this.accessTokenUri = JinesDefaults.Security.ClientAuthorization.accessTokenUri;
                    this.tokenServiceId = JinesDefaults.Security.ClientAuthorization.tokenServiceId;
                    this.clientId = JinesDefaults.Security.ClientAuthorization.clientId;
                    this.clientSecret = JinesDefaults.Security.ClientAuthorization.clientSecret;
                }

                public String getAccessTokenUri() {
                    return this.accessTokenUri;
                }

                public String getTokenServiceId() {
                    return this.tokenServiceId;
                }

                public String getClientId() {
                    return this.clientId;
                }

                public String getClientSecret() {
                    return this.clientSecret;
                }

                public void setAccessTokenUri(String accessTokenUri) {
                    this.accessTokenUri = accessTokenUri;
                }

                public void setTokenServiceId(String tokenServiceId) {
                    this.tokenServiceId = tokenServiceId;
                }

                public void setClientId(String clientId) {
                    this.clientId = clientId;
                }

                public void setClientSecret(String clientSecret) {
                    this.clientSecret = clientSecret;
                }
            }
        }

        public static class Http {
            private final MyProperties.Http.Cache cache = new MyProperties.Http.Cache();
            private boolean useUndertowUserCipherSuitesOrder = true;
            public MyProperties.Http.Version version;

            public Http() {
                this.version = JinesDefaults.Http.version;
            }

            public MyProperties.Http.Cache getCache() {
                return this.cache;
            }

            public boolean isUseUndertowUserCipherSuitesOrder() {
                return this.useUndertowUserCipherSuitesOrder;
            }

            public MyProperties.Http.Version getVersion() {
                return this.version;
            }

            public void setUseUndertowUserCipherSuitesOrder(boolean useUndertowUserCipherSuitesOrder) {
                this.useUndertowUserCipherSuitesOrder = useUndertowUserCipherSuitesOrder;
            }

            public void setVersion(MyProperties.Http.Version version) {
                this.version = version;
            }

            public static class Cache {
                private int timeToLiveInDays = 1461;

                public Cache() {
                }

                public int getTimeToLiveInDays() {
                    return this.timeToLiveInDays;
                }

                public void setTimeToLiveInDays(int timeToLiveInDays) {
                    this.timeToLiveInDays = timeToLiveInDays;
                }
            }

            public static enum Version {
                V_1_1,
                V_2_0;

                private Version() {
                }
            }
        }
}
